﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.Services;
using System.Globalization;
using Public;

namespace WebsiteAdmin.Salomon.AdInfo.Handler
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class Create : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int rtn = 0;
            if (Cookie.AdminLoginName != null || Cookie.AdminLoginName != "")
            {

                int txbCatID = Convert.ToInt32(context.Request["CatID"].Trim(), CultureInfo.InvariantCulture);
                int txbAdType = Convert.ToInt32(context.Request["AdType"].Trim(), CultureInfo.InvariantCulture);
                string txbAdTitle = context.Request["AdTitle"].Trim();					//介绍标题
                string txbKeywords = context.Request["Keywords"].Trim();//介绍标题
                string txbDescription = context.Request["Description"].Trim();					//介绍标题            
                string txbImgURL = context.Request["ImgURL"].Trim();
                string txbAdContent = context.Request["AdContent"].Trim();
                string txbStartDate = context.Request["StartDate"].Trim();
                string txbEndDate = context.Request["EndDate"].Trim();

                rtn = DoInsert(
                    txbCatID,
                    txbAdType,
                    txbAdTitle,
                    txbKeywords,
                    txbDescription,
                    txbImgURL,
                    txbAdContent,
                    txbStartDate,
                    txbEndDate
                );
            }
            context.Response.Write((rtn == 1) ? "{ \"Done\": \"Success\" }" : "{ \"Done\": \"Failed\" }");
            HttpContext.Current.ApplicationInstance.CompleteRequest();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        private static int DoInsert(
                int txbCatID,
                int txbAdType,
                string txbAdTitle,
                string txbKeywords,
                string txbDescription,
                string txbImgURL,
                string txbAdContent,
                string txbStartDate,
                string txbEndDate
            )
        {
            return
                Bll.CategoryAd.Insert(
                    Global.ConSalomon,
                    txbCatID,
                    txbAdType,
                    txbAdTitle,
                    txbKeywords,
                    txbDescription,
                    txbImgURL,
                    txbAdContent,
                    txbStartDate,
                    txbEndDate
                );
        }
    }
}

